var express = require('express');
var router = express.Router();

let mongoose = require('mongoose');
let jsonwebtoken = require('jsonwebtoken')
router.post('/login', async function (req, res) {
  let re = await mongoose.model('userObj').find({
    account: req.body.account,
    passworld: req.body.pasworld
  })
  if (re.length > 0) {
    const token=jsonwebtoken.sign(
      {user:re[0]},
      'chen',
      {expiresIn:'1 days'}
    );
    res.send({
      mess: "登录成功",
      data:token,
      status:200
    });
  } else {
    res.send({
      mess: "登录失败，账户或密码错误"
    });
  }

});

module.exports = router;
